$(function(){
	
	//提交作品 确认	
	$('.submitalbum').on('click',".comfirm_submit ",function(){
		var orderno=$(".orderinput").val();		
		var mobileno=$(".telinput").val();
		var wangwangno=$(".alyinput").val();
		//var orderreg=/^\d{17}$/.test(orderno);
		var orderreg=(/^(\d{11}|\d{17,18})$/).test(orderno);
		var mobilereg = /^1\d{10}$/; //验证规则
		if(orderno==""){
			$(".orderinputtips").html("请填写订单编号");
		}else if(mobileno==""){
			$(".orderinputtips").html("请填写手机号码");
		}else if(wangwangno==""){
			$(".orderinputtips").html("请填写旺旺号");
		}else{
			if(!orderreg){
				$(".orderinputtips").html('订单编号不正确');
			}else if(!mobilereg.test(mobileno)){
				$(".orderinputtips").html('手机号码不正确');
			}else{	
				var a={order_sn:orderno,mobile:mobileno,wangwang:wangwangno};
				$("#loadtoast").show();
				baseAjax('/other/third','POST',a,function(data){
					if(data.code==200){	
						var orderdata=data.data;
						work_id=orderdata.id;
						max_image_number=orderdata.max_image_number;
					 	$(".max_image_number").html(max_image_number);
					 	//获取已经上传的图片
	 					getrealdlyimage();
					 	$(".image_num").html();
					 	document.title='图片上传';
					 	$("#loadtoast").hide();
					 	$(".orderinput,.telinput,.alyinput").val('');
					 	$(".orderinputtips").html('');
					 	$(".submitalbum").hide();
					 	$(".upload_imagebox").show();
					 	
					}
					
				})
			}
		}
		
	})
	
	//返回	
	/*$('.submitalbum').on('click',".back_submit ",function(){
		window.opener=null;
		window.open('','_self');
		window.close();
	})*/
	
	
	$('#uploaderFiles').on('click',".weui-icon-warn",function(){
		$(".dialog_txt").html('照片像素过低可能导致，图片模糊')
		$(".dialog_tips").fadeIn();
		setTimeout(function(){$(".dialog_tips").fadeOut();},1000)
	})
	
})

//获取判断已经上传的图片是否已经达到最大值
function checkmax_image_number(){
	var num=$("#uploaderFiles li").length;
	$(".uploader__input_file,.close_uploadimage").css("display",num<max_image_number?'block':'none');	
	$(".close_uploadimage").css("display",num<max_image_number?'none':'block');
	$(".image_num").html(num)
}

//获取已经上传的图片
function getrealdlyimage(){
	$("#uploaderFiles").empty();
	baseAjax('other/third/third_work_image','GET',{third_work_id:work_id},function(data){
		var image_list=data.data;
		for(var i=0;i<image_list.length;i++){			
			var item=image_list[i];
			var li_detial='';
			if(item.quality!=0){//照片的一边小于900    照片像素过低可能导致，图片模糊   0=正常；1=比例不符合；2=像素不符合
				li_detial='<div class="weui-uploader__file-content"><i class="weui-icon-warn"></i></div>';
			}
			
			var	lis='<li class="weui-uploader__file '+(li_detial!=''?'weui-uploader__file_status':'')+'" quality="'+item.quality+'"   style="background-image:url('+item.image_url+'79x79)">'+li_detial+'</li>';			
			$("#uploaderFiles").append(lis);
			
		}
		checkmax_image_number();
	})
	
}
